package batch.home;

import javax.xml.parsers.*;

import org.xml.sax.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.util.Date;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;

import java.util.Vector;
import java.util.Properties;
import java.util.logging.Logger;
import java.io.*;
import java.net.*;

import java.sql.*;
import java.net.URL;
import batch.common.db.ConnectionManager;

import batch.common.report.*;

public class makeCpHtmlTur
{
    final String strJavaName = "CP Html Turkey";
    final int    ILENG       = 5;

    private final String TODAY              = DateFormatUtils.format(new Date(), "yyyyMMdd");  //Get Current Date
    private final String MAILSUBJECT        = "TUR CP Html Batch Error(" + TODAY + ")";
    private final String FILE_PATH          = "/home02/nas/tur_pub/sm3/batch/html/";
    private final String ROOT_URL    = "http://www.samsungmobile.com.tr";

    String strContentName = "";
    String strPreviewUrl = "";
    String strContentID = "";
    String strUrl = "";
    
    String content_id = "";
    String content_name = "";
    String preview_url = "";
    String order_url = "";
    String content_link = "";
    String content_price = "";
    String more_link = "";
    
    String Phone_model = "";    
    String CP_URL = "http://funclub.tr.samsungmobile.com/xml/xml.jsp?NUM=5&MODEL=";
    
    private StringBuffer sHtml = new StringBuffer();

    public makeCpHtmlTur(){
    	Homeinit();
    	Productinit();
    }
    public void Homeinit(){
        BufferedReader bfrString = null;
        StringBuffer sbfXml = new StringBuffer();

        Document doc = null;
        NodeList nlTemp = null;
        NodeList nlTemp2 = null;
    	
        OutputStreamWriter fw = null;
        
        try{
        	URL url = new URL("http://funclub.tr.samsungmobile.com/xml/xml.jsp?NUM="+ILENG);
			HttpURLConnection con = (HttpURLConnection)url.openConnection();
				
			//Logger.getLogger("home.tur_home").info("Response code from '"+url.toString()+"': "+con.getResponseCode() 
			//		+ "("+con.getResponseMessage()+")");
			
			bfrString = new BufferedReader(new InputStreamReader(con.getInputStream(), "ISO-8859-1"));
	
            String line = "";
            Vector vtElem        = new Vector();
            Vector vGames        = new Vector();
            Vector vRingtone     = new Vector();
            Vector vPolytone     = new Vector();
            Vector vVideo		 = new Vector();
            Vector vWallpapers   = new Vector();
            Vector vFeaVideo	 = new Vector();	            
            Vector vTmpMore		 = new Vector();

            while ((line = bfrString.readLine()) != null)
            {
                sbfXml.append(line);
            }

            byte bxml[] = sbfXml.toString().getBytes("ISO-8859-1");
            ByteArrayInputStream is = new ByteArrayInputStream(bxml);

            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            doc = docBuilder.parse(new InputSource(is));
            Element elem = doc.getDocumentElement();
            elem.normalize();

            nlTemp = elem.getChildNodes();
            
                for(int x=0;x<nlTemp.getLength();x++){
                    if(nlTemp.item(x).getChildNodes().getLength() > 0){
                        vtElem.addElement(nlTemp.item(x).getChildNodes());
                    }
                }
                
                for(int x=0;x<vtElem.size();x++){
                    Element tmpElem = (Element)vtElem.elementAt(x);
                    String strElem = tmpElem.getTagName();

                    //Logger.getLogger("home.tur_home").info("-------------- "+strElem+" --------------");
                    
                    nlTemp2 = tmpElem.getElementsByTagName("more_link");
                    String more_tmp = nlTemp2.item(0).getFirstChild().getNodeValue();
                    
                    vTmpMore.add(more_tmp); // More Link 
                    
                    for (int i = 0; i < ILENG; i++) {
                        Properties pptNode = new Properties();
                        
                        nlTemp = tmpElem.getElementsByTagName("content_id");
                        
                        if(nlTemp.getLength() < i || nlTemp.getLength() == 0) {
                        	Logger.getLogger("home.tur_home").info("Section '"+strElem+"' contains only "+nlTemp.getLength()+" elements.");
                        	break;
                        }
                        pptNode.setProperty("content_id", nlTemp.item(i).getFirstChild().getNodeValue());
                        nlTemp = tmpElem.getElementsByTagName("content_name");
                        pptNode.setProperty("content_name", nlTemp.item(i).getFirstChild().getNodeValue());
                        nlTemp = tmpElem.getElementsByTagName("preview_url");
                        pptNode.setProperty("preview_url", nlTemp.item(i).getFirstChild().getNodeValue());
                        nlTemp = tmpElem.getElementsByTagName("order_url");
                        pptNode.setProperty("order_url", nlTemp.item(i).getFirstChild().getNodeValue());
                        nlTemp = tmpElem.getElementsByTagName("content_link");
                        pptNode.setProperty("content_link", nlTemp.item(i).getFirstChild().getNodeValue());                        
                        nlTemp = tmpElem.getElementsByTagName("content_price");
                        pptNode.setProperty("content_price", nlTemp.item(i).getFirstChild().getNodeValue());

                        pptNode.setProperty("more_link", more_tmp);
                        
                        if(strElem.equals("game")){
                            vGames.addElement(pptNode);
                        }	                        
                        if(strElem.equals("truetone")){
                            vRingtone.addElement(pptNode);
                        }
                        if(strElem.equals("polymelodi")){
                        	vPolytone.addElement(pptNode);
                        }
                        if(strElem.equals("video")){
                        	vVideo.addElement(pptNode);
                        }
                        if(strElem.equals("animatedpicture")){
                        	vFeaVideo.addElement(pptNode);
                        }
                        if(strElem.equals("wallpaper")){
                        	vWallpapers.addElement(pptNode);
                        }	                        
                  }
                }

            File fl = new File(FILE_PATH);

            if(!fl.isDirectory()){
                fl.mkdirs();
            }

            if(vGames.size() > 0){
            	getGameHomeMain(vGames,vTmpMore);
            }
            if(vRingtone.size() > 0){
            	getRealToneHomeMain(vRingtone,vTmpMore);
            	getPressRealTone(vRingtone,vTmpMore);
            }
            if(vPolytone.size() > 0){
            	getPolyToneHomeMain(vPolytone,vTmpMore);
            }	            
            if(vVideo.size() > 0){
            	getVideoHomeMain(vVideo,vTmpMore);
            }
            if(vFeaVideo.size() > 0){
            	getFeaVideoHomeMain(vFeaVideo,vTmpMore);
            	getPressPicture(vFeaVideo,vTmpMore);
            }	            
            if(vWallpapers.size() > 0){
            	getPressWallpaper(vWallpapers,vTmpMore);
            }
	            
        }catch(Exception ex){
            ex.printStackTrace();
            Logger.getLogger("home.tur_home").info(ex.toString());
            ReportError.byEmail(MAILSUBJECT, ex.toString());
        }finally {
            if(bfrString != null) try { bfrString.close(); } catch (Exception e) {}
        }
    }
    
    
    
    public void Productinit(){
    	BufferedReader bfrString = null;

        String musicToneHtml = "";
        String GameHtml = "";
        String WallpaperHtml = "";
    	
        StringBuffer sQuery = new StringBuffer()
        .append("SELECT PHONE_MODEL FROM G_SFC_PRODUCT              \n")
        .append("   WHERE SITE_CD='tur' and display_flag = 'Y' \n");        
        
        Connection conn   = null;
        Statement  stmt   = null;
        ResultSet  rs     = null;
        OutputStreamWriter fw = null;
        
        try{

        	conn = ConnectionManager.getConnection();
            conn.setAutoCommit(true);
            stmt= conn.createStatement();
            rs = stmt.executeQuery(sQuery.toString());
            while (rs.next()) {
            	
            	StringBuffer sbfXml = null;
                bfrString = null;
                sbfXml = new StringBuffer();

                Document doc = null;
                NodeList nlTemp = null;            	
                NodeList nlTemp2 = null;
                
            	ByteArrayInputStream is = null;
            	URLConnection urlCon = null;
            	
            	Phone_model   = ObjectUtils.toString(rs.getObject(1));
            	
            	//System.out.println("CP_URL=========="+CP_URL+Phone_model);            	

	            //HTTP Connection
	//            URLConnection urlCon = new URL("http://premium.za.samsungmobile.com/samsung/servlet/XMLServlet/GetAllContentList?NUM=" + ILENG).openConnection();
	            urlCon = new URL(CP_URL+Phone_model).openConnection();
	
	            bfrString = new BufferedReader(new InputStreamReader(urlCon.getInputStream(), "ISO-8859-1"));
	
	            String line = "";
	            Vector vtElem        = new Vector();
	            Vector vRingtone     = new Vector();
	            Vector vWallpapers   = new Vector();
	            Vector vGames        = new Vector();
	
	            while ((line = bfrString.readLine()) != null)
	            {
	                sbfXml.append(line);
	            }
	            
	            byte bxml[] = sbfXml.toString().getBytes("ISO-8859-1");
	            
	            is = new ByteArrayInputStream(bxml);
	
	            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
	            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
	            
	            doc = docBuilder.parse(new InputSource(is));
	            Element elem = doc.getDocumentElement();
	            elem.normalize();
	
	            nlTemp = elem.getChildNodes();
	            
	                for(int x=0;x<nlTemp.getLength();x++){
	                    if(nlTemp.item(x).getChildNodes().getLength() > 0){
	                        vtElem.addElement(nlTemp.item(x).getChildNodes());
	                    }
	                }
	                
	                for(int x=0;x<vtElem.size();x++){
	                    Element tmpElem = (Element)vtElem.elementAt(x);
	                    String strElem = tmpElem.getTagName();
	                    
	                    //Logger.getLogger("home.tur_home").info("-------- "+strElem+" --------");

                        //nlTemp = tmpElem.getElementsByTagName("more_link");	                    
                        nlTemp2 = tmpElem.getElementsByTagName("more_link");
	                    String more_tmp = nlTemp2.item(0).getFirstChild().getNodeValue();
                        
	                    for (int i = 0; i < ILENG; i++) {
	                        Properties pptNode = new Properties();
	                        
	                        nlTemp = tmpElem.getElementsByTagName("content_id");
	                        
	                        if(nlTemp.getLength() < i || nlTemp.getLength() == 0) {
	                        	Logger.getLogger("home.tur_home").info(Phone_model+": Section '"+strElem+"' contains only "+nlTemp.getLength()+" elements.");
	                        	break;
	                        }
	                        
	                        pptNode.setProperty("content_id", nlTemp.item(i).getFirstChild().getNodeValue());
	                        nlTemp = tmpElem.getElementsByTagName("content_name");
	                        pptNode.setProperty("content_name", nlTemp.item(i).getFirstChild().getNodeValue());
	                        nlTemp = tmpElem.getElementsByTagName("preview_url");
	                        pptNode.setProperty("preview_url", nlTemp.item(i).getFirstChild().getNodeValue());
	                        nlTemp = tmpElem.getElementsByTagName("order_url");
	                        pptNode.setProperty("order_url", nlTemp.item(i).getFirstChild().getNodeValue());
	                        nlTemp = tmpElem.getElementsByTagName("content_link");
	                        pptNode.setProperty("content_link", nlTemp.item(i).getFirstChild().getNodeValue());                        
	                        nlTemp = tmpElem.getElementsByTagName("content_price");
	                        pptNode.setProperty("content_price", nlTemp.item(i).getFirstChild().getNodeValue());
	                        
	                        pptNode.setProperty("more_link", more_tmp);
	                        
	                        if(strElem.equals("polymelodi")){
	                            vRingtone.addElement(pptNode);
	                        }

	                        if(strElem.equals("game")){
	                            vGames.addElement(pptNode);
	                        }	                        
	                        
	                        if(strElem.equals("wallpaper")){
	                            vWallpapers.addElement(pptNode);
	                        }
	                  }
	                }
	
	            File fl = new File(FILE_PATH);
	
	            if(!fl.isDirectory()){
	                fl.mkdirs();
	            }

	            if(vRingtone.size() > 0){
	            	musicToneHtml = getCpHtmlMusicTone(vRingtone,Phone_model);
	            }	            
	            if(vGames.size() > 0){
	            	GameHtml = getCpHtmlGames(vGames,Phone_model);
	            }
	            if(vWallpapers.size() > 0){
	            	WallpaperHtml = getCpHtmlWallpaper(vWallpapers,Phone_model);
	            }
	            
	            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH+ "/phone/"+Phone_model+".html",false), "utf-8");
	            fw.write(musicToneHtml+GameHtml+WallpaperHtml);
	            fw.close();	            

            } //while End
	            
        }catch(Exception ex){
            ex.printStackTrace();
            Logger.getLogger("home.tur_home").info(ex.toString());
            ReportError.byEmail(MAILSUBJECT, ex.toString());
        }finally {
            if(bfrString != null) try { bfrString.close(); } catch (Exception e) {}
            if (fw != null) try { fw.close(); } catch (Exception e) {}
            if(rs        != null) try { rs.close();        } catch(Exception se) {}
            if(stmt      != null) try { stmt.close();      } catch(Exception se) {}
            if(conn      != null) try { conn.close();      } catch(Exception se) {}            
        }
    }
    
    public String getCpHtmlMusicTone(Vector pVector, String Phone_model) throws Exception {

        String htmlCpAll = "";
        try{
            sHtml.setLength(0);

            sHtml.append("<ol class='cList' id='dtCon_1'>\n");
            
            if(pVector.size() > 0) {
            	
            	for(int i=0; i<pVector.size(); i++){
                Properties pContentList = (Properties) pVector.elementAt(i);

                more_link  = StringUtils.defaultString(pContentList.getProperty("more_link"),"");
                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");                
 
	                if(content_name.length() >= 23){
	                	content_name = content_name.substring(0, 23) + "..";
	                }                
                
                	sHtml.append("	<li>\n")
		            	.append("	<span class='t_no'></span>\n")
		            	.append("	<a href=\"javascript:goOrder('"+order_url+"');\" style='cursor:pointer'>\n")
		            	.append(content_name)
		            	.append("	</a>\n")
		            	.append("	<span class='ico'><img id=\"rightBtnMusic"+(i+1)+"\" src=\"/image/common/btn_sound_off.gif\" alt='' onClick=\"rightPlayMusic('"+(i+1)+"');\" alt='play' title='play' style=cursor:pointer>\n")
		            	.append("	<input type=\"hidden\" name=\"filepath"+(i+1)+"\"  value=\"\" >\n")
		            	.append("	<input type=\"hidden\" name=\"filename"+(i+1)+"\"  value=\""+preview_url+"\" >\n")
		            	.append("	<input type=\"hidden\" name=\"artist"+(i+1)+"\"    value=\"\" >\n")
		            	.append("	<input type=\"hidden\" name=\"title"+(i+1)+"\"     value=\""+content_name+"\" >\n")
		            	.append("	<input type=\"hidden\" name=\"order_url"+(i+1)+"\" value=\""+order_url+"\" >\n")
		            	.append("	</span>\n")
		            	.append("	</li>\n");						
            	}
            }
            sHtml.append("</ol>\n");
        	htmlCpAll = sHtml.toString();            
            
        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return htmlCpAll;
    }    
    
    
    public String getCpHtmlGames(Vector pVector, String Phone_model) throws Exception {

        String htmlCpAll = "";
        try{
            sHtml.setLength(0);
            sHtml.append("<div id='dtCon_2' style='display:none'>\n");
            
            if(pVector.size() > 0) {
            	
            	for(int i=0; i<2; i++){
                Properties pContentList = (Properties) pVector.elementAt(i);

                more_link  = StringUtils.defaultString(pContentList.getProperty("more_link"),"");
                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");                
 
	                if(content_name.length() >= 13){
	                	content_name = content_name.substring(0, 13) + "..";
	                }                
                
                	sHtml.append("<div class='prdInfo mb5'>\n")
		                .append("<div class='imgBox50'><a href=javascript:goOrder('"+order_url+"');><img src="+preview_url+" alt="+content_name+" title="+content_name+" width=50 height=50></a></div>\n")
		                .append("<div class='list'>\n")
		                .append("		<p class='p_tit' onclick=goOrder('"+order_url+"');>\n")
		                .append("				<a href=javascript:goOrder('"+order_url+"'); style=cursor:pointer >"+content_name+"</a>\n")
		                .append("		</p>\n")
		                .append("		<p class='p_btnA'>\n")
		                .append("			<img src=/image/common/btn_detail.gif style=cursor:pointer alt=DETAY onclick=goOrder('"+content_link+"');><br>\n")
		                .append("			<img src=/image/common/btn_buy.gif style=cursor:pointer alt=Satın Al onClick=goOrder('"+content_link+"');>\n")
		                .append("		</p>\n")
		                .append("	</div>\n")
		                .append("</div>\n");
            	}
            }
        	sHtml.append("</div>\n");
        	htmlCpAll = sHtml.toString();
        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return htmlCpAll;
    }     

    public String getCpHtmlWallpaper(Vector pVector, String Phone_model) throws Exception {

        String htmlCpAll = "";
        try{
            sHtml.setLength(0);
            sHtml.append("<div id='dtCon_3' style='display:none'>\n");
            
            if(pVector.size() > 0) {
            	
            	for(int i=0; i<2; i++){
                Properties pContentList = (Properties) pVector.elementAt(i);

                more_link  = StringUtils.defaultString(pContentList.getProperty("more_link"),"");
                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");                
 
                if(content_name.length() >= 13){
                	content_name = content_name.substring(0, 13) + "..";
                }                
                
                sHtml.append("	<div class='prdInfo mb5'>\n")
                .append("	<div class='imgBox50'><img src="+preview_url+" alt="+content_name+" title="+content_name+" width=50 height=50 onclick=goOrder('"+order_url+"'); style=cursor:pointer></div>\n")
                .append("	<div class='list'>\n")
                .append("	<p class='p_tit' onclick=goOrder('"+order_url+"'); style=cursor:pointer>\n")
                .append("		<a href=javascript:goOrder('"+order_url+"'); style=cursor:pointer>"+content_name+"</a>\n")
                .append("		</p>\n")
                .append("		<p class='p_btnA'>\n")
                .append("		<img src=/image/common/btn_detail.gif style=cursor:pointer alt='DETAY' onclick=goOrder('"+content_link+"');><br>\n")
                .append("		<img src=/image/common/btn_buy.gif style=cursor:pointer alt='Satın Al' onclick=goOrder('"+order_url+"');>\n")
                .append("		</p>\n")
                .append("	</div>\n")
                .append("	</div>\n");
            	}
            }
        	sHtml.append("</div>\n");
        	htmlCpAll = sHtml.toString();
        }catch(Exception ex){
        	ex.printStackTrace();
        }
        return htmlCpAll;
    }    

    
    // FRONT MAIN HTML
    public void getGameHomeMain(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;

        String moreLink = "";
        if (vMore != null || vMore.equals("")) moreLink = (String)vMore.elementAt(5);
        
        try{
            /* Front MAIN Page Game*/
            sHtml.setLength(0);
            
            sHtml.append("<form name=mobileFrm id=mobileFrm method=post action=/link.do?goPage="+moreLink+">")
            .append("<dt>\n")
            .append("<a href='/link.do?goPage="+moreLink+"'>Oyunlar</a><a href='/link.do?goPage="+moreLink+"' class='more'>devamı</a>\n")
            .append("</dt>\n")
            .append("<dd class='mCon'>\n")
            .append("	<div class='goodsList'>\n")
            .append("		<ul>\n");

            if(pVector.size() > 0) {
            	for(int i=0; i<pVector.size(); i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
	                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
	                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
	                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");            
	            
	                if(content_name.length() >= 13){
	                	content_name = content_name.substring(0, 13) + "..";
	                } 	                	                
	                
		            sHtml.append("			<li>\n")
			             .append("				<div class='imgBox77'><a href=javascript:detail('"+content_link+"');><img src='"+preview_url+"' alt='"+content_name+"' width=77 height=77></a></div>\n")
			             .append("				<p class='p_tit'>"+content_name+" </p>\n")
			             .append("				<div class='p_btnA'>\n")
			             .append("					<a href=javascript:detail('"+content_link+"');><img src="+ROOT_URL+"/image/common/btn_detail.gif alt='Info'></a>\n")
			             .append("					<a href=javascript:detail('"+order_url+"');><img src="+ROOT_URL+"/image/common/btn_buy.gif alt='Satın Al'></a>\n")
			             .append("				</div>\n")
			             .append("			</li>\n");
            	}
            }
            sHtml.append("		</ul>\n")
            .append("	</div>\n")
            .append("</form>\n")            
            .append("</dd>\n");
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/homegame_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }    

    public void getRealToneHomeMain(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;

        String moreLink = "";
        if (vMore != null || vMore.equals("")) moreLink = (String)vMore.elementAt(3);        
        
        try{
            /*RINGTONE*/
            sHtml.setLength(0);
            
            sHtml.append("<dl class='mboxG'>\n")
            .append("	<dt>\n")
            .append("		Gerçek Sesler<a href='/link.do?goPage="+moreLink+"' class='more'>devamı</a>\n")
            .append("	</dt>\n")
            .append("	<dd>\n")
            .append("		<ul class='dotList'>\n");

            if(pVector.size() > 0) {
            	for(int i=0; i<pVector.size(); i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                more_link  = StringUtils.defaultString(pContentList.getProperty("more_link"),"");
	                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
	                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
	                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
	                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");            

	                if(content_name.length() >= 21){
	                	content_name = content_name.substring(0, 21) + "..";
	                }	                
	                
	                sHtml.append("			<li>\n")		
		                 .append("				<a href=\"javascript:goOrder('"+content_link+"');\">"+content_name+"</a>\n")
		                 .append("				<div class='p_btnA'>\n")
		                 .append("					<img  id=\"btnMusic"+(i+1)+"\" src=\""+ROOT_URL+"/image/common/btn_sound_off.gif\" onClick=\"musicPlayMusic('"+(i+1)+"');\" style='cursor:pointer'>\n")
		                 .append("					<a href=\"javascript:goOrder('"+order_url+"');\"><img src=\""+ROOT_URL+"/image/common/btn_buy.gif\" alt='Satın Al'></a>\n")
		                 .append("				</div>\n")
		                 .append("				<input type=\"hidden\" name=\"filepath"+(i+1)+"\"   id=\"filepath"+(i+1)+"\"  	value=\"\" >\n")
		                 .append("				<input type=\"hidden\" name=\"filename"+(i+1)+"\"   id=\"filename"+(i+1)+"\"  	value=\""+preview_url+"\" >\n")
		                 .append("				<input type=\"hidden\" name=\"artist"+(i+1)+"\"     id=\"artist"+(i+1)+"\" 		value=\"\" >\n")
		                 .append("				<input type=\"hidden\" name=\"title"+(i+1)+"\"      id=\"title"+(i+1)+"\" 		value=\""+content_name+"\" >\n")
		                 .append("				<input type=\"hidden\" name=\"order_url"+(i+1)+"\"  id=\"order_url"+(i+1)+"\" 	value=\""+order_url+"\" >\n")
		                 .append("			</li>\n");
            	}
            }
            sHtml.append("		</ul>\n")
            .append("	</dd>\n")
            .append("</dl>\n");            
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/homeringtone_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }    

    
    public void getPolyToneHomeMain(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;

        String moreLink = "";
        if (vMore != null || vMore.equals("")) moreLink = (String)vMore.elementAt(4);        
        
        try{
            /*RINGTONE*/
            sHtml.setLength(0);
            
            sHtml.append("<dl class='mboxG'>\n")
            	 .append("	<dt>PolyMelodiler <a href=/link.do?goPage="+moreLink+" class='more'>devamı</a></dt>\n")
            	 .append("	<dd>\n")
            	 .append("		<ul class=dotList>\n");

            if(pVector.size() > 0) {
            	for(int i=0; i<pVector.size(); i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                more_link  = StringUtils.defaultString(pContentList.getProperty("more_link"),"");
	                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
	                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
	                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
	                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");            

	                if(content_name.length() >= 21){
	                	content_name = content_name.substring(0, 21) + "..";
	                }	                
	                
	                sHtml.append("			<li>\n")		
		                 .append("				<a href=\"javascript:goOrder('"+content_link+"');\">"+content_name+"</a>\n")
		                 .append("				<div class=\"p_btnA\">\n")
		                 .append("					<img  id=\"btnMusic"+(i+6)+"\" src=\""+ROOT_URL+"/image/common/btn_sound_off.gif\" onClick=\"musicPlayMusic('"+(i+6)+"');\" style='cursor:pointer'>\n")
		                 .append("					<a href=\"javascript:goOrder('"+order_url+"');\"><img src=\""+ROOT_URL+"/image/common/btn_buy.gif\" alt=\"Satın Al\"></a>\n")
		                 .append("				</div>\n")
		                 .append("				<input type=\"hidden\" name=\"filepath"+(i+6)+"\"   id=\"filepath"+(i+6)+"\"  	value=\"\" >\n")
		                 .append("				<input type=\"hidden\" name=\"filename"+(i+6)+"\"   id=\"filename"+(i+6)+"\"  	value=\""+preview_url+"\" >\n")
		                 .append("				<input type=\"hidden\" name=\"artist"+(i+6)+"\"     id=\"artist"+(i+6)+"\" 		value=\"\" >\n")
		                 .append("				<input type=\"hidden\" name=\"title"+(i+6)+"\"      id=\"title"+(i+6)+"\" 		value=\""+content_name+"\" >\n")
		                 .append("				<input type=\"hidden\" name=\"order_url"+(i+6)+"\"  id=\"order_url"+(i+6)+"\" 	value=\""+order_url+"\" >\n")
		                 .append("			</li>\n");
            	}
            }
            sHtml.append("		</ul>\n")
            	 .append("	</dd>\n")
                 .append("</dl>\n");            
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/homepolytone_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }    

    public void getVideoHomeMain(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;

        String moreLink = "";
        if (vMore != null || vMore.equals("")) moreLink = (String)vMore.elementAt(0);        
        
        try{
            /*RINGTONE*/
            sHtml.setLength(0);
            
            sHtml.append("<dt><a href='/link.do?goPage="+moreLink+"'>Videolar</a> <a href='/link.do?goPage="+moreLink+"' class='more'>devamı</a></dt>\n")
            .append("<dd class='wBg rCon'>\n")
            .append("	<ul class='prdInfo'>\n");

            if(pVector.size() > 0) {
            	for(int i=0; i<3; i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                more_link  = StringUtils.defaultString(pContentList.getProperty("more_link"),"");
	                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
	                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
	                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
	                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");            

	                if(content_name.length() >= 21){
	                	content_name = content_name.substring(0, 21) + "..";
	                } 	                	                
	                
	                sHtml.append("		<li>\n")
		                 .append("			<div class='imgBox50'>\n")
		                 .append("				<img src="+preview_url+" alt= width=50 height=50>\n")
		                 .append("				<div class='btn_play'><a href=javascript:detail('"+content_link+"');><img src="+ROOT_URL+"/image/common/btn_moviePlayS.gif alt='play'></a></div>\n")
		                 .append("			</div>\n")
		                 .append("			<div class='list'>\n")
		                 .append("				<p class='p_tit'><a href=javascript:detail('"+content_link+"');>"+content_name+"</a></p>\n")
		                 .append("				<p class='p_detail'>\n")
		                 .append("					<a href=javascript:detail('"+content_link+"');><img src="+ROOT_URL+"/image/common/btn_detail.gif alt='DETAY'></a><br>\n")
		                 .append("					<a href=javascript:detail('"+order_url+"');><img src="+ROOT_URL+"/image/common/btn_buy.gif alt='Satın AL'></a>\n")
		                 .append("				</p>\n")
		                 .append("			</div>\n")
		                 .append("		</li>\n");
            	}
            }
            sHtml.append("	</ul>\n")
            	 .append("</dd>\n");            
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/homevideo_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }    
    
    public void getFeaVideoHomeMain(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;

        String moreLink = "";
        if (vMore != null || vMore.equals("")) moreLink = (String)vMore.elementAt(2);        
        
        try{
            /*RINGTONE*/
            sHtml.setLength(0);
            
            sHtml.append("<dl class='mBox200 mt5'>\n")
            .append("	<dt><a href='/link.do?goPage="+moreLink+"'>Animasyonlu Resimler</a> <a href='/link.do?goPage="+moreLink+"' class='more'>devamı</a></dt>\n")
            .append("	<dd class='wBg rCon'>\n")
            .append("		<ul class='prdInfo'>\n");

            if(pVector.size() > 0) {
            	for(int i=0; i<3; i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                more_link  = StringUtils.defaultString(pContentList.getProperty("more_link"),"");
	                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
	                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
	                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
	                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");            

	                if(content_name.length() >= 21){
	                	content_name = content_name.substring(0, 21) + "..";
	                } 	                	                
	                
	                
	                sHtml.append("		<li>\n")
		                 .append("				<div class='imgBox50'>\n")
		                 .append("					<img src="+preview_url+" alt='' width=50 height=50>\n")
		                 .append("					<div class='btn_play'><a href=javascript:detail('"+content_link+"');><img src="+ROOT_URL+"/image/common/btn_moviePlayS.gif alt='play'></a></div>\n")
		                 .append("				</div>\n")
		                 .append("				<div class='list'>\n")
		                 .append("					<p class='p_tit'><a href=javascript:detail('"+content_link+"');>"+content_name+"</a></p>\n")
		                 .append("					<p class='p_detail'>\n")
		                 .append("						<a href=javascript:detail('"+content_link+"');><img src="+ROOT_URL+"/image/common/btn_detail.gif alt='DETAY'></a><br>\n")
		                 .append("						<a href=javascript:detail('"+order_url+"');><img src="+ROOT_URL+"/image/common/btn_buy.gif alt='Satın AL'></a>\n")
		                 .append("					</p>\n")
		                 .append("				</div>\n")
		                 .append("			</li>\n");
            	}
            }
            sHtml.append("		</ul>\n")
            	 .append("	</dd>\n")
            	 .append("</dl>\n");            
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/homefeaturevideo_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }

    public void getPressRealTone(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;

        String moreLink = "";
        if (vMore != null || vMore.equals("")) moreLink = (String)vMore.elementAt(2);        
        
        try{
            /*RINGTONE*/
            sHtml.setLength(0);
            
            sHtml.append("<dt><a href='/link.do?goPage="+moreLink+"'>Yeni Gerçek Sesler</a>\n")
            .append("<a href='/link.do?goPage="+moreLink+"' class='more'>devamı</a>\n")
            .append("</dt>\n")
            .append("<dd class='dd_realtoneChart'>\n")
            .append("	<div class='topSeller'>\n")
            .append("		<ol class='cList'>\n");

            if(pVector.size() > 0) {
            	for(int i=0; i<5; i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                more_link  = StringUtils.defaultString(pContentList.getProperty("more_link"),"");
	                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
	                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
	                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
	                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");            
	            
	                if(content_name.length() >= 21){
	                	content_name = content_name.substring(0, 21) + "..";
	                } 	                
	                
	                sHtml.append("		<li>\n")
		                 .append("			<span class='t_no'></span>\n")
		                 .append("			<a href=\"javascript:goOrder('"+content_link+"');\" style=\"cursor:pointer\">"+(i+1)+". "+content_name+"</a>\n")
		                 .append("			<span class=\"ico\"><img id=\"rightBtnMusic"+(i+1)+"\" src='"+ROOT_URL+"/image/common/btn_sound_off.gif' alt=\"\" onClick=\"rightPlayMusic('"+(i+1)+"');\" alt=\"play\" title=\"play\" style=\"cursor:pointer\">\n")
		                 .append("			<input type=\"hidden\" name=\"filepath"+(i+1)+"\"  value=\"\" >\n")
		                 .append("			<input type=\"hidden\" name=\"filename"+(i+1)+"\"  value=\""+preview_url+"\" >\n")
		                 .append("			<input type=\"hidden\" name=\"artist"+(i+1)+"\"    value=\"\" >\n")
		                 .append("			<input type=\"hidden\" name=\"title"+(i+1)+"\"     value=\""+content_name+"\" >\n")
		                 .append("			<input type=\"hidden\" name=\"order_url"+(i+1)+"\" value=\""+order_url+"\" >\n")
		                 .append("			</span>\n")
		                 .append("			</li>\n");
            	}
            }
            sHtml.append("		</ol>\n")
            	 .append("	</div>\n")
            	 .append("</dd>\n");            
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/pressrealtone_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }    

    public void getPressWallpaper(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;

        String moreLink = "";
        if (vMore != null || vMore.equals("")) moreLink = (String)vMore.elementAt(2);        
        
        try{
            /*RINGTONE*/
            sHtml.setLength(0);
            
            sHtml.append("<dt>\n")
            .append("<a href='/link.do?goPage="+moreLink+"'>Yeni Duvar Kağıtları</a>\n")
            .append("<a href='/link.do?goPage="+moreLink+"' class='more'>devamı</a></dt>\n")
            .append("</dt>\n")
            .append("<dd class='dd_ranking'>\n")
            .append("<div class='topSeller'>\n");

            if(pVector.size() > 0) {
            	for(int i=0; i<2; i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                more_link  = StringUtils.defaultString(pContentList.getProperty("more_link"),"");
	                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
	                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
	                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
	                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");            
	            
	                sHtml.append("	<div class='prdInfo mb5'>\n")
		                 .append("		<div class='imgBox50'><img src="+preview_url+" alt="+content_name+" title="+content_name+" width=50 height=50 onclick=goOrder('"+order_url+"'); style='cursor:pointer'></div>\n")
		                 .append("		<div class='list'>\n")
		                 .append("			<p class='p_tit' onclick=goOrder('"+order_url+"'); style=cursor:pointer>\n")
		                 .append("					<a href=javascript:goOrder('"+order_url+"'); style=cursor:pointer>"+content_name+"</a>\n")
		                 .append("			</p>\n")
		                 .append("			<p class='p_btnA'>\n")
		                 .append("				<img src="+ROOT_URL+"/image/common/btn_detail.gif style=cursor:pointer alt=DETAY onclick=goOrder('"+content_link+"');><br>\n")
		                 .append("				<img src="+ROOT_URL+"/image/common/btn_buy.gif style=cursor:pointer alt=Satın Al onclick=goOrder('"+order_url+"');>\n")
		                 .append("			</p>\n")
		                 .append("		</div>\n")
		                 .append("	</div>\n");
            	}
            }
            sHtml.append("</div>\n")
            	 .append("</dd>\n");            
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/presswallpaper_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }    

    public void getPressPicture(Vector pVector, Vector vMore) throws Exception  {
        OutputStreamWriter fw = null;

        String moreLink = "";
        if (vMore != null || vMore.equals("")) moreLink = (String)vMore.elementAt(2);        
        
        try{
            /*RINGTONE*/
            sHtml.setLength(0);
            
            sHtml.append("<dt>\n")
            .append("<a href='/link.do?goPage="+moreLink+"'>Yeni Animasyonlu Resimler</a>\n")
            .append("<a href='/link.do?goPage="+moreLink+"' class='more'>devamı</a></dt>\n")
            .append("</dt>\n")
            .append("<dd class='dd_ranking'>\n")
            .append("<div class='topSeller'>\n");

            if(pVector.size() > 0) {
            	for(int i=0; i<2; i++){
	                Properties pContentList = (Properties) pVector.elementAt(i);
	                more_link  = StringUtils.defaultString(pContentList.getProperty("more_link"),"");
	                content_id = StringUtils.defaultString(pContentList.getProperty("content_id"),"");
	                content_name = StringUtils.defaultString(pContentList.getProperty("content_name"),"");
	                preview_url = StringUtils.defaultString(pContentList.getProperty("preview_url"),"");
	                order_url = StringUtils.defaultString(pContentList.getProperty("order_url"),"");
	                content_link = StringUtils.defaultString(pContentList.getProperty("content_link"),"");
	                content_price = StringUtils.defaultString(pContentList.getProperty("content_price"),"");            
	            
	                sHtml.append("	<div class='prdInfo mb5'>\n")
		                 .append("		<div class='imgBox50'><img src="+preview_url+" alt="+content_name+" title="+content_name+" width=50 height=50 onclick=goOrder('${graphicsbean.order_url}'); style=cursor:pointer></div>\n")
		                 .append("		<div class='list'>\n")
		                 .append("			<p class='p_tit' onclick=goOrder('"+order_url+"'); style=cursor:pointer>\n")
		                 .append("			<a href=javascript:goOrder('"+order_url+"'); style=cursor:pointer>"+content_name+"</a>\n")
		                 .append("			</p>\n")
		                 .append("			<p class='p_btnA'>\n")
		                 .append("				<img src="+ROOT_URL+"/image/common/btn_detail.gif style='cursor:pointer' alt='DETAY' onclick=goOrder('"+content_link+"');><br>\n")
		                 .append("			    <img src="+ROOT_URL+"/image/common/btn_buy.gif style='cursor:pointer' alt='Satın Al' onclick=goOrder('"+order_url+"');>\n")
		                 .append("			</p>\n")
		                 .append("		</div>\n")
		                 .append("	</div>\n");
            	}
            }
            sHtml.append("</div>\n")
            	 .append("</dd>\n");            
            
            fw = new OutputStreamWriter(new FileOutputStream(FILE_PATH + "/presspicture_include.html",false), "utf-8");
            fw.write(sHtml.toString());
            fw.close();

        }finally{
            if (fw != null) try { fw.close(); } catch (Exception e) {}
        }
    }
    
    
    
    
    public static void main( String[] args ){
      Logger.getLogger("home.tur_home").info("( * ) Start.");
      makeCpHtmlTur mvm = new makeCpHtmlTur();
      Logger.getLogger("home.tur_home").info("( * ) End.");
    }
}